#include "Stage.h"
#include "StageSketcher.h"

Stage::Stage() {
	this->setType("Stage");
	this->sketcher = new StageSketcher(this);
}

Stage::~Stage() {
	
	delete(this->frog);
	delete(this->rail);
	delete(this->drainage);
	delete(sketcher);
}

/*-------------Getters & Setters--------------------*/


void Stage::addElement(Element * element){
	if(element->getType().compare("Frog")==0) {
		this->frog=(Frog*)element;
	}
	if(element->getType().compare("Drainage")==0) {
		this->drainage=(Drainage*)element;
	}
	if(element->getType().compare("Rail")==0) {
		this->rail=(Rail*)element;
	}
}


Frog* Stage::getFrog(){
	return this->frog;
}
Rail* Stage::getRail(){
	return this->rail;
}
Drainage* Stage::getDrainage(){
	return this->drainage;
}
void Stage::setDrainage(Drainage * drainage){
	this->drainage = drainage;
}

void Stage::setFrog(Frog* frog){
	this->frog = frog;
}

void Stage::setRail(Rail* rail){
	this->rail = rail;
}

void Stage::setPosition(Position *position){
	this->position = position;
}

Position *Stage::getPosition(){
	return this->position;
}

Color * Stage::getElementColor(){
	return this->elementColor;
}

void Stage::setElementColor(Color * color){
	this->elementColor = color;
}

Texture *Stage::getTexture(){
	return this->texture;
}

void Stage::setTexture(Texture *texture){
	this->texture = texture;
}

Color * Stage::getLineColor()
{
	return this->lineColor;
}

void Stage::setLineColor( Color * color )
{
	this->lineColor = color;
}

Resolution * Stage::getResolution( void )
{
	return this->resolution;
}

void Stage::setResolution( Resolution * resolution )
{
	this->resolution = resolution;
}

float Stage::getMinXPos(){
	return this->getPosition()->getAxisX();
}
	
float Stage::getMinYPos(){	
	return this->getPosition()->getAxisY();
}
	
float Stage::getMaxXPos(){	
	return this->getPosition()->getAxisX();
}
	
float Stage::getMaxYPos(){
	return this->getPosition()->getAxisY();
}

void Stage::draw(){
	
	Ball * ball = getFrog()->getMainBall();
	/*este metodo podria ir en otro thread*/
	Position pClear;
	pClear.setPixel(ball->getPosition()->getPixelX() - ball->getRadius(),ball->getPosition()->getPixelY() - ball->getRadius());
	SketcherHelper::getInstance()->clearBackground(&pClear,ball->getRadius()*2,ball->getRadius()*2);
	ball->move();
	ball->draw();
	SketcherHelper::getInstance()->show();
	
}

void Stage::initialize(void){
	sketcher->draw();
	SketcherHelper::getInstance()->show();
	delete(sketcher);
}